package com.example.demo07cache.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * @author 王迅
 */
@Slf4j
@Component
public class RedisChannelListener implements MessageListener {

    @Override
    public void onMessage(Message message, byte[] pattern) {
        // "15830340927-9"
        String body = new String(message.getBody(), StandardCharsets.UTF_8);
        // cleanNoStockCache
        String channel = new String(message.getChannel(), StandardCharsets.UTF_8);
        // cleanNoStockCache
        String strPattern = new String(pattern, StandardCharsets.UTF_8);
        log.info("----body----: {}", body);
        log.info("----channel----: {}", channel);
        log.info("----strPattern----: {}", strPattern);
    }
}
